package org.hsieh.tr.explore.ui.actions.dbview;

import java.io.FileOutputStream;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.hsieh.tr.explore.dbsource.DatabaseInfoManager;
import org.hsieh.tr.explore.exception.ExceptionHandler;
import org.hsieh.tr.explore.util.ApplicationUtil;

public class ExportAction extends Action implements IWorkbenchAction {
	public void init() {

	}

	public ExportAction() {
		super();
		setText("Export DB information");
	}

	@Override
	public void run() {
		FileDialog dialog = new FileDialog(PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getShell(), SWT.SAVE);
		String filePath = dialog.open();
		if (filePath != null) {
			try {
				ApplicationUtil.objectToOutputStream(
						DatabaseInfoManager.INSTANCE.getInfos(),
						new FileOutputStream(filePath));
			} catch (Exception e) {
				ExceptionHandler.handle(e);
			}
		}
	}

	public void dispose() {

	}

}
